package com.example.backend.dto;

import com.example.backend.domain.enums.TicketPriority;
import com.example.backend.domain.enums.TicketStatus;
import lombok.Data;

import java.time.Instant;
import java.util.List;
import java.util.Map;

/**
 * 高级搜索请求DTO
 */
@Data
public class AdvancedSearchRequest {
    
    // 基础搜索条件
    private String keyword;
    private List<TicketStatus> statuses;
    private List<TicketPriority> priorities;
    private List<Long> assignedToIds;
    private List<Long> customerIds;
    private List<Long> categoryIds;
    private List<String> sources;
    
    // 时间范围搜索
    private Instant createdStartDate;
    private Instant createdEndDate;
    private Instant updatedStartDate;
    private Instant updatedEndDate;
    private Instant dueStartDate;
    private Instant dueEndDate;
    
    // 数值范围搜索
    private Integer minSatisfactionScore;
    private Integer maxSatisfactionScore;
    private Double minEstimatedHours;
    private Double maxEstimatedHours;
    private Double minActualHours;
    private Double maxActualHours;
    
    // 布尔条件搜索
    private Boolean isPublic;
    private Boolean isEscalated;
    private Boolean hasComments;
    private Boolean hasAttachments;
    
    // 全文检索
    private String fullTextSearch;
    private List<String> searchFields; // 指定搜索字段
    
    // 自定义字段筛选
    private Map<String, Object> customFields;
    
    // 逻辑组合
    private String logicOperator; // AND, OR
    private List<SearchGroup> searchGroups; // 分组搜索条件
    
    // 排序和分页
    private String sortBy;
    private String sortDirection; // ASC, DESC
    private Integer page;
    private Integer size;
    
    // 搜索条件保存
    private String saveAsName;
    private String saveDescription;
    private Boolean isPublicSave;
    
    /**
     * 搜索分组
     */
    @Data
    public static class SearchGroup {
        private String groupName;
        private String groupLogicOperator; // AND, OR
        private List<SearchCondition> conditions;
    }
    
    /**
     * 搜索条件
     */
    @Data
    public static class SearchCondition {
        private String field;
        private String operator; // EQUALS, NOT_EQUALS, CONTAINS, NOT_CONTAINS, GREATER_THAN, LESS_THAN, BETWEEN, IN, NOT_IN
        private Object value;
        private Object secondValue; // 用于BETWEEN操作
    }
}
